Type.registerNamespace("AjaxControlToolkit");
AjaxControlToolkit.TextBoxWatermarkBehavior = function(c) 
{
		var b = null, a = this; 
		AjaxControlToolkit.TextBoxWatermarkBehavior.initializeBase(a, [c]);
		a._watermarkText = b;
		a._watermarkCssClass = b;
		a._focusHandler = b;
		a._blurHandler = b;
		a._keyPressHandler = b;
		a._propertyChangedHandler = b;
		a._watermarkChangedHandler = b;
		a._oldClassName = b;
		a._clearedForSubmit = b;
		a._maxLength = b;
		if (typeof WebForm_OnSubmit == "function" && !AjaxControlToolkit.TextBoxWatermarkBehavior._originalWebForm_OnSubmit)
		{
			AjaxControlToolkit.TextBoxWatermarkBehavior._originalWebForm_OnSubmit = WebForm_OnSubmit;
			WebForm_OnSubmit = AjaxControlToolkit.TextBoxWatermarkBehavior.WebForm_OnSubmit
		}
};

AjaxControlToolkit.TextBoxWatermarkBehavior.prototype = {
	initialize: function() 
	{
		var a = this;
		AjaxControlToolkit.TextBoxWatermarkBehavior.callBaseMethod(a, "initialize");
		var b = a.get_element(), e = false, c = AjaxControlToolkit.TextBoxWatermarkBehavior.callBaseMethod(a, "get_ClientState");
		if (c != null && c != "") 
		{
			e = c == "Focused";
			AjaxControlToolkit.TextBoxWatermarkBehavior.callBaseMethod(a, "set_ClientState", null)
		}
		a._oldClassName = b.className;
		a._focusHandler = Function.createDelegate(a, a._onFocus);
		a._blurHandler = Function.createDelegate(a, a._onBlur);
		a._keyPressHandler = Function.createDelegate(a, a._onKeyPress);
		$addHandler(b, "focus", a._focusHandler);
		$addHandler(b, "blur", a._blurHandler);
		$addHandler(b, "keypress", a._keyPressHandler);
		a.registerPropertyChanged();
		var f = AjaxControlToolkit.TextBoxWrapper.get_Wrapper(a.get_element()).get_Current(), d = AjaxControlToolkit.TextBoxWrapper.get_Wrapper(a.get_element());
		if ("" == f || a._watermarkText == f) 
		{
			d.set_Watermark(a._watermarkText);
			d.set_IsWatermarked(true)
		}
		if (e) 
			a._onFocus();
		else 
		{
			b.blur();
			a._onBlur()
		}
		a._clearedForSubmit = false;
		a.registerPartialUpdateEvents();
		a._watermarkChangedHandler = Function.createDelegate(a, a._onWatermarkChanged);
		d.add_WatermarkChanged(a._watermarkChangedHandler)	},

	dispose: function() 
	{
		var b = null, a = this, c = a.get_element();
		if (a._watermarkChangedHandler) 
		{
			AjaxControlToolkit.TextBoxWrapper.get_Wrapper(a.get_element()).remove_WatermarkChanged(a._watermarkChangedHandler);
			a._watermarkChangedHandler = b
		}
		if (c.control && a._propertyChangedHandler) 
		{
			c.control.remove_propertyChanged(a._propertyChangedHandler);
			a._propertyChangedHandler = b
		}
		if (a._focusHandler) 
		{
			$removeHandler(c, "focus", a._focusHandler);
			a._focusHandler = b
		}
		if (a._blurHandler) 
		{
			$removeHandler(c, "blur", a._blurHandler);
			a._blurHandler = b
		}
		if (a._keyPressHandler) 
		{
			$removeHandler(c, "keypress", a._keyPressHandler);
			a._keyPressHandler = b
		}
		if (AjaxControlToolkit.TextBoxWrapper.get_Wrapper(a.get_element()).get_IsWatermarked()) 
			a.clearText(false);
		AjaxControlToolkit.TextBoxWatermarkBehavior.callBaseMethod(a, "dispose")
	},

	_onWatermarkChanged: function() 
	{
		if (AjaxControlToolkit.TextBoxWrapper.get_Wrapper(this.get_element()).get_IsWatermarked())
			this._onBlur();
		else
			this._onFocus()
	},

	clearText: function(c) 
	{
		var a = this.get_element(), b = AjaxControlToolkit.TextBoxWrapper.get_Wrapper(a);
		b.set_Value("");
		b.set_IsWatermarked(false);
		if (c) 
		{
			a.setAttribute("autocomplete", "off");
			a.select()
		}	},

	_onFocus: function(c) 
	{
		var a = this, b = a.get_element();
		if (AjaxControlToolkit.TextBoxWrapper.get_Wrapper(b).get_IsWatermarked()) 
			a.clearText(c ? true : false);
		b.className = a._oldClassName;
		if (a._maxLength > 0) 
		{
			a.get_element().maxLength = a._maxLength;
			a._maxLength = null
		}
	},

	_onBlur: function() 
	{
		var a = this, b = AjaxControlToolkit.TextBoxWrapper.get_Wrapper(a.get_element());
		if ("" == b.get_Current() || b.get_IsWatermarked()) 
		{
			if (a.get_element().maxLength > 0 && a._watermarkText.length > a.get_element().maxLength) 
			{
				a._maxLength = a.get_element().maxLength;
				a.get_element().maxLength = a._watermarkText.length
			} 
			a._applyWatermark()
		}
	},

	_applyWatermark: function() 
	{
		var a = this, b = AjaxControlToolkit.TextBoxWrapper.get_Wrapper(a.get_element());
		b.set_Watermark(a._watermarkText);
		b.set_IsWatermarked(true);
		if (a._watermarkCssClass) 
			a.get_element().className = a._watermarkCssClass
	},

	_onKeyPress: function() 
	{
		AjaxControlToolkit.TextBoxWrapper.get_Wrapper(this.get_element()).set_IsWatermarked(false)
	},

	registerPropertyChanged: function() 
	{
		var a = this, b = a.get_element();
		if (b.control && !a._propertyChangedHandler)
		{
			a._propertyChangedHandler = Function.createDelegate(a, a._onPropertyChanged);
			b.control.add_propertyChanged(a._propertyChangedHandler)
		}
	},

	_onPropertyChanged: function(b, a) 
	{
	if ("text" == a.get_propertyName())
		this.set_Text(AjaxControlToolkit.TextBoxWrapper.get_Wrapper(this.get_element()).get_Current())
	},

	_onSubmit: function() 
	{
		if (AjaxControlToolkit.TextBoxWrapper.get_Wrapper(this.get_element()).get_IsWatermarked()) 
		{
			this.clearText(false);
			this._clearedForSubmit = true
		}
	},

	_partialUpdateEndRequest: function(c, b) 
	{
		var a = this;
		AjaxControlToolkit.TextBoxWatermarkBehavior.callBaseMethod(a, "_partialUpdateEndRequest", [c, b]);
		if (a.get_element() && a._clearedForSubmit) 
		{
			a.get_element().blur();
			a._onBlur();
			a._clearedForSubmit = false
		}
	},

	get_WatermarkText: function() 
	{
		return this._watermarkText
	},

	set_WatermarkText: function(b) 
	{
		var a = this;
		if (a._watermarkText != b) 
		{
			a._watermarkText = b;
			if (AjaxControlToolkit.TextBoxWrapper.get_Wrapper(a.get_element()).get_IsWatermarked()) 
				a._applyWatermark();
			a.raisePropertyChanged("WatermarkText")
		}
	},

	get_WatermarkCssClass: function() 
	{
		return this._watermarkCssClass	},

	set_WatermarkCssClass: function(b) 
	{
		var a = this;
		if (a._watermarkCssClass != b) 
		{
			a._watermarkCssClass = b;
			if (AjaxControlToolkit.TextBoxWrapper.get_Wrapper(a.get_element()).get_IsWatermarked())
				a._applyWatermark(); 
			a.raisePropertyChanged("WatermarkCssClass")
		}
	},

	get_Text: function() 
	{
		return AjaxControlToolkit.TextBoxWrapper.get_Wrapper(this.get_element()).get_Value()
	},

	set_Text: function(b) 
	{
		var a = this;
		if ("" == b) 
		{
			AjaxControlToolkit.TextBoxWrapper.get_Wrapper(a.get_element()).set_Current("");
			a.get_element().blur();
			a._onBlur()
		}
		else 
		{
			a._onFocus();
			AjaxControlToolkit.TextBoxWrapper.get_Wrapper(a.get_element()).set_Current(b)
		}
	}
};

AjaxControlToolkit.TextBoxWatermarkBehavior.registerClass("AjaxControlToolkit.TextBoxWatermarkBehavior", AjaxControlToolkit.BehaviorBase);

AjaxControlToolkit.TextBoxWatermarkBehavior.WebForm_OnSubmit = function() 
{
	var d = AjaxControlToolkit.TextBoxWatermarkBehavior._originalWebForm_OnSubmit();
	if (d) 
	{
		var b = Sys.Application.getComponents();
		for (var a = 0; a < b.length; a++) 
		{
			var c = b[a];
			if (AjaxControlToolkit.TextBoxWatermarkBehavior.isInstanceOfType(c))
				c._onSubmit()
		}
	}
	return d
};